//2486
package L2;

import java.util.Scanner;

/**
 * Author:Feng Guoyu
 */
public class TestMatrix {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        int i = 3;
        int j = 4;
        Matrix mat = new Matrix(i, j);
        for (int ind_i = 0;ind_i<i;++ind_i) {
            for (int ind_j = 0;ind_j <j;++ind_j)
                mat.setPos(ind_i, ind_j, sc.nextInt());
        }
        sc.close();
        Matrix matT = Matrix.transpose(mat);
        Matrix mult = mat.rightMultiplyBy(matT);
        System.out.println("Original matrix:");
        mat.display();
        System.out.println("Transpose:");
        matT.display();
        System.out.println("Matrix multiplication:");
        mult.display();
    }
}


class Matrix {
    private int i;
    private int j;
    private int[][] arr;
    public void setPos(int i, int j, int v) {
        arr[i][j] = v;
    }
    public int getVal(int i, int j){
        return arr[i][j];
    }
    public static Matrix transpose(Matrix mat) {
        Matrix matT = new Matrix(mat.j, mat.i);
        for (int ind_i = 0; ind_i < mat.i; ind_i++) {
            for (int ind_j = 0; ind_j < mat.j; ind_j++)
                matT.setPos(ind_j, ind_i, mat.getVal(ind_i, ind_j));
        }
        return matT;
    }
    public Matrix rightMultiplyBy(Matrix mat) {
        Matrix m = new Matrix(i, mat.j);
        for (int ind_i = 0; ind_i < i; ind_i++) {
            for (int ind_j = 0; ind_j < mat.j; ind_j++) {
                int sum = 0;
                for (int p = 0;p < mat.i;++p)
                    sum += this.getVal(ind_i, p) * mat.getVal(p, ind_j);
                m.setPos(ind_i, ind_j, sum);
            }
        }
        return m;
    }
    Matrix(int i, int j){
        this.i = i;
        this.j = j;
        arr = new int[i][j];
    }
    Matrix(int i, int j, int[][] arr){
        this.i = i;
        this.j = j;
        this.arr = arr;
    }
    public void display() {
        for (int ind_i = 0; ind_i < i; ind_i++) {
            for (int ind_j = 0; ind_j < j; ind_j++)
                System.out.print(""+arr[ind_i][ind_j]+"\t");
            System.out.println();
        }
    }
}